<?php
/**
 * Created by PhpStorm.
 * User: tonyliangli
 * Date: 2016/10/20
 * Time: 16:11
 */

namespace Api\Controller;

use Think\Controller;

class LoginController extends CommonController {

    /**
     * 登录
     */
    public function login() {

        $mobile = I('post.mobile');
        $password = I('post.password');

        $serviceMap['mobile'] = $mobile;
        $service = D("service")->where($serviceMap)->find();

        //判断用户是否存在
        if(isNullOrEmpty($service)) {
            $this->errorReturn('ERROR_SERVICE_NOT_FOUND');
        }

        //判断密码是否正确
        if(md5($password) != $service['password']) {
            $this->errorReturn('ERROR_SERVICE_NOT_FOUND');
        }

        $this->returnData['values']['token'] = $service['token'];

        $this->response($this->returnData,'json');

    }

}